from django.test import TestCase

from hony.models import ArticleModels, ArticleContentModel, AuthorModel

# Create your tests here.

class ArtcileSaveTest(TestCase):
    
    def test_article_save_content_more(self):
        '''测试正文超500 字符的状态'''
        content = 'a' * 600
        author, _ = AuthorModel.objects.get_or_create()
        data = {
            "title":"测试title",
            "tags": "测试tag",
            "author": author,
            "content": content
        }
        ArticleModels.objects.get_or_create(**data) 
        self.assertEquals(ArticleModels.objects.all().count(), 1, '文章插入异常')
        self.assertEqual(ArticleModels.objects.all().first().title, data.get('title'), msg='标题插入异常')
        self.assertEqual(ArticleModels.objects.all().first().tags, data.get('tags'), msg='tags插入异常')
        self.assertEqual(ArticleModels.objects.all().first().author, data.get('author'), msg='作者插入异常')
        self.assertEqual(ArticleModels.objects.all().first().content, '-1', msg='正文插入异常')
        self.assertEqual(ArticleContentModel.objects.all().count(), 1, msg='文章正文插入异常')
        self.assertEqual(ArticleContentModel.objects.all().first().content, data.get('content'), msg='文章正文插入异常')
        

    def test_article_save_content_less(self):
        '''测试 正文吧不超过500字符状态'''
        content = 'a' * 200
        author, _ = AuthorModel.objects.get_or_create()
        data = {
            "title":"",
            "tags": "",
            "author": author,
            "content": content
        }
        ArticleModels.objects.get_or_create(**data)
        self.assertEqual(ArticleModels.objects.all().count(), 1, msg='文章插入异常')
        self.assertEquals(ArticleModels.objects.all().count(), 1, '文章插入异常')
        self.assertEqual(ArticleModels.objects.all().first().title, data.get('title'), msg='标题插入异常')
        self.assertEqual(ArticleModels.objects.all().first().tags, data.get('tags'), msg='tags插入异常')
        self.assertEqual(ArticleModels.objects.all().first().author, data.get('author'), msg='作者插入异常')
        self.assertEqual(ArticleModels.objects.all().first().content, data.get('content'), msg='正文插入异常')
        self.assertEqual(ArticleContentModel.objects.all().count(), 0, msg='文章正文插入异常')
